package framework {
	import flash.display.DisplayObjectContainer;
	import framework.controller.RetrieveContentCommand;
	import framework.service.BlitParser;
	import framework.service.BlitRetrieverService;
	import framework.service.IParser;
	import framework.service.IRetrieverService;
	import framework.service.LoaderSignalsWrapper;
	import framework.service.RetrievalDataStore;
	import framework.signals.RegisterBlitDisplayObjectSignal;
	import framework.signals.RetrieveContentSignal;
	import framework.view.BlitCanvasMediator;
	import framework.view.BlitCanvasView;
	import framework.view.BlitDisplayObjectMediator;
	import framework.view.BlitDisplayObjectView;
	import framework.view.CoreMediator;
	import framework.view.Profiler;
	import framework.view.ProfilerMediator;
	import org.robotlegs.mvcs.SignalContext;

	/**
	 * @author Charlie MacIsaac
	 */
	
	public class CoreContext extends SignalContext {
		// PROPERTIES =============================================================================
		// GETTERS + SETTERS ======================================================================
		// CONSTRUCTOR ============================================================================
		public function CoreContext(contextView : DisplayObjectContainer) {
			super(contextView);
		}
		
		// PUBLIC =================================================================================
		override public function startup() : void {
			// == PROFILER ===================================================================
			mediatorMap.mapView(Profiler, ProfilerMediator);
			
			// == CORE LOADER PROCESS ========================================================
			// RetrieveContentSignal will use the mapped IRetrieverService to fetch content
			signalCommandMap.mapSignalClass(RetrieveContentSignal, RetrieveContentCommand);
			// LoaderSignalsWrapper wraps the Adobe Loader / URLLoader to use signals
			injector.mapClass(LoaderSignalsWrapper, LoaderSignalsWrapper);
			// The retrieval service stores the parsed data in here
			injector.mapSingleton(RetrievalDataStore);
			// The IRetrieverService will use the IParser to map the content to a suitable class
			// For blitting (PNG image + JSON data sheet)
			injector.mapClass(IRetrieverService, BlitRetrieverService);
			injector.mapClass(IParser, BlitParser);
			// For single files
			//injector.mapClass(IRetrieverService, FileRetrieverService);
			//injector.mapClass(IParser, FileParser);
			
			// == BLITTING ===================================================================
			// BlitDisplayObjectView will not trigger a mediator map as it is not a DisplayObject
			mediatorMap.mapView(BlitDisplayObjectView, BlitDisplayObjectMediator, BlitDisplayObjectView, false, false);
			// Once created the BlitDisplayObjectMediator will dispatch a RegisterBlitDisplayObjectSignal
			injector.mapSingleton(RegisterBlitDisplayObjectSignal);
			// The Canvas listens to the signal RegisterBlitDisplayObjectSignal and registers it to be drawn
			mediatorMap.mapView(BlitCanvasView, BlitCanvasMediator);
			
			// == LOCAL ======================================================================
			// The CoreMediator starts the test process
			mediatorMap.mapView(CoreRobotlegs, CoreMediator, CoreRobotlegs, false, false);
			mediatorMap.createMediator(contextView);
		}
		
		// PRIVATE ================================================================================
		// LISTENERS ==============================================================================
	}
}